"""
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""

import paddle

from fastdeploy.platforms import current_platform

if current_platform.is_cuda():
    from fastdeploy.model_executor.ops.gpu import (
        get_block_shape_and_split_kv_block as get_block_shape_and_split_kv_block_cuda,
    )


def get_block_shape_and_split_kv_block(
    seq_lens_encoder: paddle.Tensor,
    seq_lens_decoder: paddle.Tensor,
    seq_lens_this_time: paddle.Tensor,
    decoder_batch_ids: paddle.Tensor,
    decoder_tile_ids_per_batch: paddle.Tensor,
    decoder_num_blocks_cpu: paddle.Tensor,
    decoder_num_blocks_device: paddle.Tensor,
    decoder_chunk_size_device: paddle.Tensor,
    max_len_tensor_cpu: paddle.Tensor,
    encoder_batch_ids: paddle.Tensor,
    encoder_tile_ids_per_batch: paddle.Tensor,
    encoder_num_blocks_x_cpu: paddle.Tensor,
    kv_batch_ids: paddle.Tensor,
    kv_tile_ids_per_batch: paddle.Tensor,
    kv_num_blocks_x_cpu: paddle.Tensor,
    max_len_kv_cpu: paddle.Tensor,
    encoder_block_shape_q: int,
    decoder_block_shape_q: int,
    group_size: int,
    block_size: int,
    decoder_step_token_num: int,
):
    """
    get_block_shape_and_split_kv_block
    """
    if current_platform.is_cuda():
        get_block_shape_and_split_kv_block_cuda(
            seq_lens_encoder,
            seq_lens_decoder,
            seq_lens_this_time,
            decoder_batch_ids,
            decoder_tile_ids_per_batch,
            decoder_num_blocks_cpu,
            decoder_num_blocks_device,
            decoder_chunk_size_device,
            max_len_tensor_cpu,
            encoder_batch_ids,
            encoder_tile_ids_per_batch,
            encoder_num_blocks_x_cpu,
            kv_batch_ids,
            kv_tile_ids_per_batch,
            kv_num_blocks_x_cpu,
            max_len_kv_cpu,
            encoder_block_shape_q,
            decoder_block_shape_q,
            group_size,
            block_size,
            decoder_step_token_num,
        )

    else:
        raise NotImplementedError
